<?php
class Con_news extends Acan{
	public $defaultAct='manage';
	public $Conread = '新闻';
	public $Actread = array('show'=>'文章浏览','manage'=>'文章管理');
	function __construct($ainfo=null){
		parent::__construct($ainfo=null);
		$this->atitle = $this->Actread[$this->Aact];
		$this->model = Afun_db()->model(Acan_table_danhao_news);
	}
	function Act_manage(){
		$this->atitle = $this->Actread[$this->Aact];
		$this->model->comment['username'] = '用户名';
		$obj = Afun_acan_new('list');
		$column_json = $obj->form_json($this->model);
		$con->select = "a.*,b.username";
		$con->join = "LEFT JOIN `".Acan_table_user."` b ON a.uid=b.uid";
		$page->theurl = $this->Aactr.'-'.$this->id;
		$page->by = $this->model->key_name;
		$page->page = '20';
		$page->order = 'DESC';
		if($_GET['apage']>200){$_GET['apage'] = 200;}
		if ($this->_SS['uid']>0) $page->counts = $this->model->count($con);	//统计总数目
		$pages = Afun_apage($page);
		$con->order = "a.$pages->orderby";
		$con->limit = $pages->limit;
		//分页结束
		$list = $this->model->findAll($con);
		include $this->Atpl();
	}
	function Act_show(){
		$id = $this->id;
		if(!$id){$id = 1;}
		$data = $this->model->findPk($id);
		$this->atitle = $data['title'];
		include $this->Atpl();
	}
	//批量更新
	function Act_save(){
		Afun_post_auth();
		$savedata = $_POST['save'];
		$savedata['update'] = Afun_get_time();
		if($this->id == 'one'){
			$key = $savedata[$this->model->key_name];
			unset($savedata[$this->model->key_name]);
			if(!empty($key)){
				$msg = $this->model->updatePk($savedata,$key);
			}else{
				$savedata['uid'] = $this->uid;
				$msg = $this->model->save($savedata);
			}
		}
		Afun_json($msg);
	}
}

?>